package com.lz.dao.impl;

import com.lz.dao.UserDao;
import com.lz.domain.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public User FindById(int id) {
        List<User> query = jdbcTemplate.query("select * from user where id=?", new BeanPropertyRowMapper<>(User.class), id);
        User user = query.get(0);
        return user;
    }

}
